
#ifndef	__MY_MACROS
#define  __MY_MACROS

typedef	unsigned char	byte;
typedef	unsigned int 	uint;
typedef	signed char		sbyte; 
typedef	unsigned long	ulong;

#define	TRUE	1
#define	FALSE	!TRUE 

#define	INPUT		1
#define  OUTPUT	0


//#define	__25MHZ__

#ifndef	__25MHZ__

#define	MHZ	*1000L			/* number of kHz in a MHz */
#define	KHZ	*1			/* number of kHz in a kHz */

#ifndef	XTAL_FREQ
#define	XTAL_FREQ	4MHZ		/* Crystal frequency in MHz */
#endif


#if	XTAL_FREQ >= 12MHZ

#define	delay_us(x)	{ unsigned char _dcnt; \
			  _dcnt = (x)*((XTAL_FREQ)/(12MHZ)); \
			  while(--_dcnt != 0) \
				  continue; }
#else

#define	delay_us(x)	{ unsigned char _dcnt; \
			  _dcnt = (x)/((12MHZ)/(XTAL_FREQ))|1; \
			  while(--_dcnt != 0) \
				  continue; }
#endif

extern void delay_ms ( uint mSec);

#else

#define	MHZ	*1

#ifndef	XTAL_FREQ
#define	XTAL_FREQ	25MHZ		/* Crystal frequency in MHz */
#endif

#if	XTAL_FREQ < 8MHZ
#define	uS_CNT 	238			/* 4x to make 1 mSec */
#endif

#if	XTAL_FREQ == 8MHZ
#define uS_CNT  244
#endif

#if	XTAL_FREQ > 8MHZ
#define uS_CNT  240
#endif

#define FREQ_MULT	(XTAL_FREQ)/(4MHZ)

#define	delay_us(x)	{ unsigned char _dcnt; \
			  if(x>=4) _dcnt=(x*(FREQ_MULT)/2); \
			  else _dcnt=1; \
			  while(--_dcnt > 0) \
				{\
				asm("nop");\
				asm("nop");\
				continue; }\
		} 

extern void delay_ms ( uint mSec);

#endif

typedef struct {  unsigned b0 : 1;	    	
				 		unsigned b1 : 1;
				 		unsigned b2 : 1;
				 		unsigned b3 : 1;
				 		unsigned b4 : 1;
				 		unsigned b5 : 1;
				 		unsigned b6 : 1; 
				 		unsigned b7 : 1;	} BYTE ; 

typedef union { byte Byte;
					 BYTE BITS; } UBYTE; 	

#define 	setBit(reg,b)	(reg|=(1<<(b)))
#define 	clrBit(reg,b)	(reg&=(~(1<<(b))))
#define 	xorBit(reg,b)	(reg^=(1<<(b)))
#define 	readBit(reg,b)	(reg&(1<<(b)))

#define     set(BIT)		(setBit(BIT))
#define     clr(BIT)		(clrBit(BIT))
#define     xor(BIT)		(xorBit(BIT))
#define     read(BIT)	(readBit(BIT))


#ifndef NULL
#define NULL	((void*)0)			/**< NULL pointer */
#endif

#ifndef NOP
#define NOP		asm("nop")
#endif


#endif
